using Cysharp.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


//UniTask 不能await两次,状态不可逆!

// UniTask.Void 参数异步委托  直接启动一个异步委托,不考虑其等待  无需加await
// UniTask.Defer 用异步委托快速生成返回UniTask的异步方法  必须加await 才能执行
public class Five : MonoBehaviour
{
    private async void Start()
    {
        // var task = UniTask.Delay(1000);
        // await task;
        // // await task; // 状态不可逆! 不能await两次,会报错: InvalidOperationException: Token version is not matched, can not await twice or get Status after await.

        UniTask.Void(async () =>
        {
            Debug.Log("Start :" + Time.frameCount);
        
            await UniTask.NextFrame();
            Debug.Log("End :" + Time.frameCount);
        });

        await UniTask.Defer(async () =>
        {
            Debug.Log("Start :" + Time.frameCount);

            await UniTask.NextFrame();
            Debug.Log("End :" + Time.frameCount);
        });

        // UniTask.Defer 需要await 才能执行
        UniTask.Defer(async () =>
        {
            Debug.Log("Start :" + Time.frameCount);

            await UniTask.NextFrame();
            Debug.Log("End :" + Time.frameCount);
        });
    }
}